package tamagocc.util;

import java.util.Date;

import tamagocc.exception.TamagoCCException;
import tamagocc.generic.api.GType;

public abstract class TamagoCCGenUtil {

	public static String toString(GType type) throws TamagoCCException {
		switch(type.catType()) {
		case BOOL: return "boolean";
		case REAL: return "double";
		case INTEGER: return "int";
		case OBJECT: return type.getType();
		case VOID: return "void";
		case ARRAY:
			return TamagoCCGenUtil.toString(type.getArrayType())+"[]";
		default:
			throw new TamagoCCException("Unknown category of type in TamagoCCGenUtil");
		}
	}

	
	public static String headerFile(String title) {
		StringBuffer sb = new StringBuffer();
		Date now = new Date();
		sb.append("\n ******************************************\n");
		sb.append(" *");
		int flood = (40-title.length())/2;
		for(int i=0;i < flood;i++) sb.append(" ");
		sb.append(title);
		for(int i=0;i < flood;i++) sb.append(" ");
		sb.append("*\n");
		sb.append(" ******************************************\n");
		sb.append(" *\n");
		sb.append(" * DO NOT EDIT THIS FILE.\n");
		sb.append(" * THIS FILE IS GENERATED AUTOMATICALLY BY TAMAGOCC\n");
		sb.append(" * Created date : "+now.toString()+"\n");
		sb.append(" * authors : Hakim Belhaouari and Frederic Peschanski\n");
		sb.append(" * site : http://code.google.com/p/tamago/\n");
		return sb.toString();
	}
	
	public static String headerSkeletonFile(String title) {
		StringBuffer sb = new StringBuffer();
		Date now = new Date();
		sb.append("\n ******************************************\n");
		sb.append(" *");
		int flood = (40-title.length())/2;
		for(int i=0;i < flood;i++) sb.append(" ");
		sb.append(title);
		for(int i=0;i < flood;i++) sb.append(" ");
		sb.append("*\n");
		sb.append(" ******************************************\n");
		sb.append(" *\n");
		sb.append(" * YOU MUST EDIT THIS FILE.\n");
		sb.append(" * TAMAGOCC GENERATES AUTOMATICALLY THE SKELETON.\n");
		sb.append(" * Created date : "+now.toString()+"\n");
		sb.append(" * authors : Hakim Belhaouari and Frederic Peschanski\n");
		sb.append(" * site : http://code.google.com/p/tamago/\n");
		return sb.toString();
	}
}
